package com.chendongyang.www.service; //用户对充电站进行评论；
import com.chendongyang.www.dao.apprises;
import com.chendongyang.www.po.*;
import com.chendongyang.www.dao.charge;
import com.chendongyang.www.util.userId;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Scanner;

public class apprise {
    public void apprising() throws SQLException {
        apprises udi = new apprises();
        charge udi1=new charge();
        ArrayList <apprise1> list1=new ArrayList<>();
        System.out.println("请选择进行查看评论或对充电站进行评论");
        System.out.println("1     查看评论");
        System.out.println("2     进行评论");
        Scanner input = new Scanner(System.in);
        int op = input.nextInt();
        if (op == 1) {
           list1=udi.select1();
            System.out.println("充电站的评论有：");
           for(int i=0;i<list1.size();i++){
               System.out.print(i+1+"   ");
               System.out.println(list1.get(i));
           }
        } else {
            boolean check1=udi1.select2(userId.Id);
            if(check1==false){
                System.out.println("您的电动车还没有上牌，无法进行评论");
                return;
            }
            System.out.println("现有以下充电站可进行评论，请选择");
            ArrayList<String> list = udi.select();
            int sum = list.size();
          //  System.out.println(sum);
            for (int i = 0; i < sum-1; i++) {
                for (int m = sum-1; m >i; m--) {
                    if (list.get(m).equals(list.get(i))) {
                        list.remove(m);
                        sum--;
                    }
                }
            }
            sum = list.size();
            for (int i = 0; i < sum; i++) {
                System.out.println(i+1+"  充电站：" + list.get(i));
            }
            System.out.println("请选择要评论的充电站对应的选项");
            int op1=input.nextInt();
            System.out.println("请输入您的评论（限五十字内）");
            String a=input.nextLine();//吸收空格;
            String comment=input.nextLine();
            int line=udi.insert(list.get(op1-1),comment,userId.Id);
            if(line==1) System.out.println("评论成功");
            else System.out.println("评论失败");
        }
    }
}
